﻿using loginWinForm.entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using loginWinForm.dao;
using System.Data;

namespace loginWinForm.service.impl
{
    class LoginService : ILoginService
    {
        UserDao userDao = new UserDao();

        public SysUser GetUserByName(string name)
        {
            SysUser user = new SysUser();
            string sql = "SELECT * FROM SYS_USER WHERE NAME= '" + name + "'";
            DataSet ds = CommonSQLDao.GetDataSet(sql);
            foreach (DataRow row in ds.Tables[0].Rows)
            {

                user.Id = null == row["id"] ? "" : row["id"].ToString();
                user.Name = null == row["name"] ? "" : row["name"].ToString();
                user.Password = null == row["password"] ? "" : row["password"].ToString();
                user.Mc = null== row["mc"] ? "": row["mc"].ToString();

            }
            return user;
        }

        public void saveUser(SysUser user)
        {
            // 用户密码待加入 MD5 验证
            userDao.insertUser(user);
        }

        public void update(SysUser sysUser)
        {
            userDao.update(sysUser);
        }
    }
}
